<template>
  <div>
    <el-form @submit.native.prevent="saveArticle" ref="form" :model="article" label-width="80px">
      <el-form-item label="文章标题">
        <el-input v-model="article.title"></el-input>
      </el-form-item>
      <el-form-item label="文章内容">
        <el-input type="textarea" v-model="article.body"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit" @click="onSubmit">保存</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
  export default {
    data() {
      return {
        article: {
          title: '',
          body: '',
        }
      }
    },
    created() {
      this.feach()
    },
    methods: {
      feach(){
        this.$http.get(`/articles/${this.$route.params.id}`).then(res=>{
          console.log(res.data);
          this.article=res.data
        })
      },
      onSubmit() {
        console.log('xiugai!');
      },
      saveArticle(){
        //console.log(this.article);
        this.$http.put(`/articles/${this.$route.params.id}`,this.article).then((res)=>{
          console.log(res.data);
          this.$message({
            message: '文章修改成功',
            type: 'success'
          });
          this.$router.push('/articles/index')//跳转到列表
        })
      }
    }
  }
</script>